#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <list>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_Release/NetEngine_Include/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtspProtocol/RtspProtocol_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtspProtocol/RtspProtocol_Error.h"

//g++ -std=gnu++11 -Wall -g TestFor_RtspProtocol.cpp -o TestFor_RtspProtocol -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_StreamMedia -lNetEngine_BaseLib -lStreamMedia_RtpProtocol -Wl,-rpath=../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_StreamMedia,--disable-new-dtags

void TestUDP_RtspProtocol()
{
    int nMsgLen = 0;
    LPCTSTR lpszRTSPUrl = _T("rtsp://127.0.0.1/live/1");
    LPCTSTR lpszSession = _T("3B2241FA");
    TCHAR tszMsgBuffer[1024];

    RTSPPROTOCOL_REQUEST st_RtspRequest;
    RTSPPROTOCOL_RESPONSE st_RtspResponse;
    RTSPPROTOCOL_SETUP st_RtspSetup;

    memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
    memset(&st_RtspRequest, '\0', sizeof(RTSPPROTOCOL_REQUEST));
    memset(&st_RtspResponse, '\0', sizeof(RTSPPROTOCOL_RESPONSE));
    memset(&st_RtspSetup, '\0', sizeof(RTSPPROTOCOL_SETUP));

    RtspProtocol_ClientPacket_Setup(tszMsgBuffer, &nMsgLen, lpszRTSPUrl, IPPROTO_UDP, 1, 63505, 63506);
    RtspProtocol_CoreParse_Parse(&st_RtspRequest, tszMsgBuffer, nMsgLen);
    RtspProtocol_CoreHelp_Transport(st_RtspRequest.st_ExtInfo.tszTransport, &st_RtspSetup.nIPProtol, &st_RtspSetup.nClientRTPPort, &st_RtspSetup.nClientRTCPPort);

    st_RtspSetup.nServerRTPPort = 10001;
    st_RtspSetup.nServerRTCPPort = 10002;
    _tcscpy(st_RtspSetup.tszDestAddr, _T("192.168.1.108"));
    _tcscpy(st_RtspSetup.tszSourceAddr, _T("192.168.1.115"));

    RtspProtocol_CorePacket_Setup(tszMsgBuffer, &nMsgLen, lpszSession, &st_RtspSetup, st_RtspRequest.nCseq);
    RtspProtocol_ClientParse_Parse(&st_RtspResponse, tszMsgBuffer, nMsgLen);
    return;
}
void TestTCP_RtspProtocol()
{
    int nMsgLen = 0;
    LPCTSTR lpszRTSPUrl = _T("rtsp://127.0.0.1/live/1");
    LPCTSTR lpszSession = _T("3B2241FA");
    TCHAR tszMsgBuffer[1024];

    RTSPPROTOCOL_REQUEST st_RtspRequest;
    RTSPPROTOCOL_RESPONSE st_RtspResponse;
    RTSPPROTOCOL_SETUP st_RtspSetup;
    RTSPPROTOCOL_AUTHINFO st_AuthInfo;

    memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
    memset(&st_RtspRequest, '\0', sizeof(RTSPPROTOCOL_REQUEST));
    memset(&st_RtspResponse, '\0', sizeof(RTSPPROTOCOL_RESPONSE));
    memset(&st_RtspSetup, '\0', sizeof(RTSPPROTOCOL_SETUP));
    memset(&st_AuthInfo, '\0', sizeof(RTSPPROTOCOL_AUTHINFO));

    _tcscpy(st_AuthInfo.tszAuthUser, "123123aa");
    _tcscpy(st_AuthInfo.tszAuthPass, "123123");

    RtspProtocol_ClientPacket_Setup(tszMsgBuffer, &nMsgLen, lpszRTSPUrl, IPPROTO_TCP, 1, 1, 2, 3, &st_AuthInfo);
    RtspProtocol_CoreParse_Parse(&st_RtspRequest, tszMsgBuffer, nMsgLen);
    RtspProtocol_CoreHelp_Transport(st_RtspRequest.st_ExtInfo.tszTransport, &st_RtspSetup.nIPProtol, &st_RtspSetup.nClientRTPPort, &st_RtspSetup.nClientRTCPPort);

    RtspProtocol_CorePacket_Setup(tszMsgBuffer, &nMsgLen, lpszSession, &st_RtspSetup, st_RtspRequest.nCseq);
    RtspProtocol_ClientParse_Parse(&st_RtspResponse, tszMsgBuffer, nMsgLen);
    return;
}

int main()
{
    TestUDP_RtspProtocol();
    TestTCP_RtspProtocol();
    return 0;
}
